<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var validSquare = function (p1, p2, p3, p4) {
      const getLenPower = (p1, p2) => {
        const x = p1[0] - p2[0];
        const y = p1[1] - p2[1];
        return x * x + y * y;
      };
      let v1 = -1;
      let v2 = -1;
      const points = [p1, p2, p3, p4];
      for (let i = 0; i < 3; i++) {
        for (let j = i + 1; j < 4; j++) {
          let v = getLenPower(points[i], points[j]);
          if (v1 === -1 || v === v1) {
            v1 = v;
          } else if (v2 === -1 || v === v2) {
            v2 = v;
          } else {
            return false;
          }
        }
      }
      return v1 > 0 && v2 > 0;
    };
    console.log(validSquare(p1 = [0, 0], p2 = [1, 1], p3 = [1, 0], p4 = [0, 1]))
  </script>
</body>

</html>